var express = require('express');
var app = express();

app.all('*', function (req, res, next) {             //设置跨域访问
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  res.header("X-Powered-By", ' 3.2.1');
  res.header("Content-Type", "application/json;charset=utf-8");
  next();
});
var infor =  [
  {
    id:1,
    name: 'jay',
    price: 20,
    state: true,
    count: 2,
    img: 'https://t7.baidu.com/it/u=1595072465,3644073269&fm=193&f=GIF'
  },
    {
      id:2,
      name: 'jay1',
      price: 202,
      state: true,
      count: 1,
      img: 'https://t7.baidu.com/it/u=4198287529,2774471735&fm=193&f=GIF'
  }
]                    //传前端的数据




app.get('/api/info', function (req, res) {           //配置接口api
  res.status(200),
    res.json(infor)
})

//配置服务端口
var server = app.listen(8080, function () {
  var host = server.address().address;
  var port = server.address().port;
  console.log('listen at http://%s:%s', host, port)
})
